const express =require("express");
const bd=require("body-parser");
const cors=require("cors");
const  http=require("http");
let app=express();
//处理跨域问题
app.use(express.static("./"));
app.use(cors());
app.all("*",function (req,res,next) {
//通过设置响应头来给浏览器返回设置白名单让浏览器将原本跨域的响应放行!
//    设置那些URL可以跨域
    res.setHeader("Access-Control-Allow-Origin","http://localhost:63342");
    //允许我们自定义头部X-Requested-With 表示请求时由ajax发起的
    res.setHeader("Access-Control-Allow-Headers","X-Requested-With,Content-Type");
    // res.setHeader("Access-Control-Allow-Origin","http://c.m.163.com/nc/article/headline/T1348647853363/0-140.html");
    //设置允许响应的请求方式
    res.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS");
    next();
})
// app.use(bd)
let lj = "http://c.m.163.com/nc/article/headline/T1348647853363/0-140.html"
app.get("/get", function(req, res) {
    console.log('LKJAL')
    http.get(lj, function(resObj) {
        let dataObj = "";
        resObj.on("data", function(chunk) {
            dataObj += chunk;
        });
        resObj.on("end", function() {
            res.json(dataObj);
            console.log("哇哈哈");
        })
    })
});

app.listen("3311",function () {
console.log("监听中")
})